// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import qs from 'qs'

Vue.config.productionTip = false

// 设置全局导航守卫
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  var userData = localStorage.getItem('userData') || ''
  if (userData) {
    next()
  } else {
    if (to.name === 'Login') {
      next()
    } else if(to.name === 'Index'){
      next({ path: '/home' })
    }  else {
      next({ path: '/login' })
    }
  }

  // if(userData == 1) {
  //   if (to.name === 'keywordSafeguard') {
  //     next({ path: '/home' })
  //   }
  // }
})

Vue.use(ElementUI)

import '@/styles/index.scss'

// Vue.prototype.$qs = qs
Vue.prototype.$qs = qs

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
